package com.dyh.quickdemo.demos.lbdbean;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Random;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;

/*
@Author=Joey Wheeler
@Date=2020/12/30 10:57
*/
@Service
@Slf4j
public class OrderBiz {



    public void createWmsOrder(String orderId){
        thrower.accept(orderId,0);
        //coinst.run();
        log.info("创建wmsOrder {}",orderId);
    }


    public void pushToWms(String orderId){
        thrower.accept(orderId,1);
        //coinst.run();
        log.info("开始推送订单 {}",orderId);
        log.info("推送订单成功 {}",orderId);
    }

    public void updateWmsOrderStatus(String orderId){
      thrower.accept(orderId,2);
        //coinst.run();
        log.info("更新wmsOrder状态为推送成功 {}",orderId);
    }

    public static BiConsumer<String,Integer> thrower = (str,len)->{
        if (str.length()==0||str.length()<len)
            throw new RuntimeException();
    };

    public static Runnable coinst = ()->{
        Random random = new Random();
        if (random.nextInt(2)<1)
            throw new RuntimeException();
    };
}
